/*
 * Resources.java
 *
 * Created on 6 September 2006, 6:28
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package fasea.constants;

import fasea.index.CombinedAnalyzer;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.util.Version;

/**
 *
 * @author gvasil
 * @author lars-wolfram
 */
public class Constants {

    /*
     * final string variables
     */
    private final static String APP_NAME = "Fasea";
    private final static String APP_VERSION = "0.01";
    private final static String INDEX_VERSION = "0.01";
    private final static String APP_AUTHOR = "Lars Wolfram";
    private final static String APP_WEBSITE = "none";
    private final static String APP_DIRECTORY_PATH = System.getProperty("user.home")
            + File.separator + "." + APP_NAME.toLowerCase();
    private final static String LOG_DIRECTORY_NAME = "logs";
    private final static String PROPERTIES_FILE_NAME = "props";
    private static final long INDEX_EXPIRATION_TIME = 24 * 60 * 60 * 1000; //24 Stunden
    private static final int MAX_SEARCH_RESULTS = 30;
    /**
     * 
     */
    private static String INDEX_DIRECTORY_NAME = "default";
    private static String INDEX_DIRECTORY_PATH =
            Constants.APP_DIRECTORY_PATH
            + File.separator + Constants.INDEX_DIRECTORY_NAME;

    public static String getApplicationName() {
        return Constants.APP_NAME;
    }

    public static String getApplicationVersion() {
        return Constants.APP_VERSION;
    }

    public static String getIndexVersion() {
        return Constants.INDEX_VERSION;
    }

    public static String getApplicationAuthor() {
        return Constants.APP_AUTHOR;
    }

    public static String getApplicationWebsite() {
        return Constants.APP_WEBSITE;
    }

    public static String getApplicationDirectoryPath() {
        return Constants.APP_DIRECTORY_PATH;
    }

    public static String getApplicationPropertiesFilePath() {
        return Constants.INDEX_DIRECTORY_PATH + File.separator
                + Constants.PROPERTIES_FILE_NAME;
    }

    public static String getDefaultIndexDirectoryPath() {
        return Constants.INDEX_DIRECTORY_PATH + File.separator;
    }
    
    public static long getIndexExpirationTime(){
        return INDEX_EXPIRATION_TIME;
    }

    public static File getLogFile() throws IOException {

        String logDir = Constants.INDEX_DIRECTORY_PATH
                + File.separator + Constants.LOG_DIRECTORY_NAME;

        String filePath = logDir + File.separator
                + "log" + Long.toHexString(new Date().getTime()) + ".txt";

        File dir = new File(logDir);
        if (dir.exists() == false) {
            if (dir.mkdirs() == false) {
                throw new IOException("Cannot create directory '" + logDir + "'");
            }
        }

        File file = new File(filePath);

        if (file.createNewFile() == false) {
            file = null;
        }

        return file;
    }

    public static Analyzer getAnalyzer() {
        return CombinedAnalyzer.getInstance();
    }

    public static Version getLuceneVersion() {
        return Version.LUCENE_36;
    }

    /**
     * @return the MAX_SEARCH_RESULTS
     */
    public static int getMaxSearchResults() {
        return MAX_SEARCH_RESULTS;
    }
}
